home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / unix / volume15 / nroffgraphics / part01 next >
Encoding:
Internet Message Format  |  1988-06-06  |  57.2 KB

  1. Subject:  v15i046:  Tools for nroff graphics on dot-matrix printers, Part01/02
  2. Newsgroups: comp.sources.unix
  3. Sender: sources
  4. Approved: rsalz@uunet.UU.NET
  5.  
  6. Submitted-by: snark!eric (Eric Raymond)
  7. Posting-number: Volume 15, Issue 46
  8. Archive-name: nroffgraphics/part01
  9.  
  10. [  I haven't tried this.  --r$ ]
  11.  
  12. This package of nroff extension utilities enables you to do three things:
  13.  
  14. 1) Convert from old-style nroff driver tables to new-style ditroff all-ASCII
  15.    tables, and vice versa (see convtab.1)
  16.  
  17. 2) Design your own extension character sets for use with nroff on any printer
  18.    supporting an Epson MX80-compatible graphics mode, or something not too
  19.    unlike it (the beginnings of a terminfo-like specification language for
  20.    composing graphics strings from rasters are provided).
  21.  
  22. 3) Get full use of special printer highlighting and alternate fonts from nroff.
  23.  
  24. A set of 'standard' graphics for old-style nroff is provided.
  25.  
  26. he convtab(1) utility is based in part on the table/elbat toolset floated
  27. to comp.sources some time back by Matt Crawford, Ian Darwin, and Bruce
  28. Townsend. The existence of ditroff format makes their design obsolete, but
  29. important parts of their implementation live on in otread.c and otwrite.c
  30. respectively.
  31.  
  32. Their documentation warns that the format for Berkeley tab files is different
  33. and thus "this package will not work on Berkely (sic) systems without
  34. substantial hacking". The same probably applies to convtab.
  35.  
  36. #! /bin/sh
  37. # This is a shell archive.  Remove anything before this line, then unpack
  38. # it by saving it into a file and typing "sh file".  To overwrite existing
  39. # files, type "sh file -c".  You can also feed this as standard input via
  40. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  41. # will see the following message at the end:
  42. #        "End of archive 1 (of 2)."
  43. # Contents:  MANIFEST Makefile READ.ME convtab.1 convtab.c ditread.c
  44. #   ditwrite.c dotmatrix.1 escapes.c otread.c otwrite.c post.proto
  45. #   term.5 termtab.c termtab.h
  46. # Wrapped by rsalz@fig.bbn.com on Tue Jun  7 14:26:48 1988
  47. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  48. if test -f 'MANIFEST' -a "${1}" != "-c" ; then 
  49.   echo shar: Will not clobber existing file \"'MANIFEST'\"
  50. else
  51. echo shar: Extracting \"'MANIFEST'\" \(623 characters\)
  52. sed "s/^X//" >'MANIFEST' <<'END_OF_FILE'
  53. X   File Name        Archive #    Description
  54. X-----------------------------------------------------------
  55. X MANIFEST                   1    
  56. X Makefile                   1    
  57. X READ.ME                    1    
  58. X convtab.1                  1    
  59. X convtab.c                  1    
  60. X ditread.c                  1    
  61. X ditwrite.c                 1    
  62. X dotmatrix.1                1    
  63. X dotmatrix.c                2    
  64. X escapes.c                  1    
  65. X mx80.pix                   2    
  66. X otread.c                   1    
  67. X otwrite.c                  1    
  68. X post.proto                 1    
  69. X term.5                     1    
  70. X termtab.c                  1    
  71. X termtab.h                  1    
  72. END_OF_FILE
  73. if test 623 -ne `wc -c <'MANIFEST'`; then
  74.     echo shar: \"'MANIFEST'\" unpacked with wrong size!
  75. fi
  76. # end of 'MANIFEST'
  77. fi
  78. if test -f 'Makefile' -a "${1}" != "-c" ; then 
  79.   echo shar: Will not clobber existing file \"'Makefile'\"
  80. else
  81. echo shar: Extracting \"'Makefile'\" \(1390 characters\)
  82. sed "s/^X//" >'Makefile' <<'END_OF_FILE'
  83. X#
  84. X# Makefile for the nroff driver-customization tools
  85. X#
  86. XLP = mx80
  87. X
  88. XDESTDIR = /usr/lib/nterm    # ditroff systems
  89. XTABFILE = tab.$(LP)
  90. X
  91. X#DESTDIR = /usr/lib/term    # pre-ditroff systems
  92. X#TABFILE = tab$(LP)
  93. X
  94. XDEFS =
  95. XCFLAGS = $(DEFS) -O    # -DKANJI if your nroff is the international version
  96. XLDFLAGS = -s
  97. XLFLAGS = $(DEFS)
  98. X
  99. XDERIVED = $(TABFILE) $(LP).c $(LP).test
  100. X
  101. X.SUFFIXES: .1 .5 .lp
  102. X.1.lp:
  103. X    nroff -man -T$(LP) $< | $(LP) >$*.lp
  104. X.5.lp:
  105. X    nroff -man -T$(LP) $< | $(LP) >$*.lp
  106. X
  107. Xall:    convtab dotmatrix
  108. X
  109. Xinstall: $(LP) $(TABFILE)
  110. X    mv $(TABFILE) $(DESTDIR)
  111. X
  112. XCONVOBJS = termtab.o ditread.o otread.o otwrite.o ditwrite.o
  113. Xconvtab: convtab.o escapes.o $(CONVOBJS)
  114. X    $(CC) $(LFLAGS) convtab.o escapes.o $(CONVOBJS) -o convtab
  115. Xdotmatrix: dotmatrix.o escapes.o
  116. X    $(CC) $(CFLAGS) dotmatrix.o escapes.o -o dotmatrix
  117. X
  118. Xconvtab.o: convtab.c termtab.h
  119. Xtermtab.o: termtab.c termtab.h
  120. Xditread.o: ditread.c termtab.h
  121. Xotwrite.o: otwrite.c termtab.h
  122. Xditwrite.o: ditwrite.c termtab.h
  123. Xotread.o: otread.c termtab.h
  124. Xescapes.o: escapes.c
  125. Xdotmatrix.o: dotmatrix.c
  126. X
  127. X$(DERIVED): dotmatrix $(LP).pix
  128. X    dotmatrix <$(LP).pix
  129. X
  130. Xlint:    
  131. X    lint $(LFLAGS) convtab.c escapes.c $(CONVOBJS:.o=.c)
  132. X    lint $(LFLAGS) dotmatrix.c escapes.c
  133. X
  134. Xclean:
  135. X    rm -f a.out *.o $(DERIVED) $(LP).raw $(LP).lp
  136. X
  137. Xtest: $(DERIVED)
  138. X    nroff -T$(LP) $(LP).test | tee $(LP).raw | $(LP) | tee $(LP).lp | lp
  139. X
  140. Xshar:
  141. X    shar READ.ME Makefile *.[ch15] *.pix post.proto >dotmatrix.shar
  142. END_OF_FILE
  143. if test 1390 -ne `wc -c <'Makefile'`; then
  144.     echo shar: \"'Makefile'\" unpacked with wrong size!
  145. fi
  146. # end of 'Makefile'
  147. fi
  148. if test -f 'READ.ME' -a "${1}" != "-c" ; then 
  149.   echo shar: Will not clobber existing file \"'READ.ME'\"
  150. else
  151. echo shar: Extracting \"'READ.ME'\" \(1573 characters\)
  152. sed "s/^X//" >'READ.ME' <<'END_OF_FILE'
  153. XThis package of nroff extension utilities enables you to do three things:
  154. X
  155. X1) Convert from old-style nroff driver tables to new-style ditroff all-ASCII
  156. X   tables, and vice versa (see convtab.1)
  157. X
  158. X2) Design your own extension character sets for use with nroff on any printer
  159. X   supporting an Epson MX80-compatible graphics mode, or something not too
  160. X   unlike it (the beginnings of a terminfo-like specification language for
  161. X   composing graphics strings from rasters are provided).
  162. X
  163. X3) Get full use of special printer highlighting and alternate fonts from nroff.
  164. X
  165. XA set of 'standard' graphics for old-style nroff is provided.
  166. X
  167. XThe convtab(1) utility is based in part on the table/elbat toolset floated
  168. Xto comp.sources some time back by Matt Crawford, Ian Darwin, and Bruce
  169. XTownsend. The existence of ditroff format makes their design obsolete, but
  170. Ximportant parts of their implementation live on in otread.c and otwrite.c
  171. Xrespectively.
  172. X
  173. XTheir documentation warns that the format for Berkeley tab files is different
  174. Xand thus "this package will not work on Berkely (sic) systems without
  175. Xsubstantial hacking". The same probably applies to convtab. Interested parties
  176. Xare urged to send me a copy of their mods for the master version.
  177. X
  178. XThe code lints clean and has been written with (hardware) portability in mind.
  179. XIt uses a few USG-isms such as getopt(3) for which PD equivalents are
  180. Xavailable.
  181. X
  182. X      Eric S. Raymond
  183. X      UUCP:  {{seismo,ihnp4,rutgers}!cbmvax,sdcrdcf!burdvax,vu-vlsi}!snark!eric
  184. X      Post:  22 South Warren Avenue, Malvern, PA 19355    Phone: (215)-296-5718
  185. END_OF_FILE
  186. if test 1573 -ne `wc -c <'READ.ME'`; then
  187.     echo shar: \"'READ.ME'\" unpacked with wrong size!
  188. fi
  189. # end of 'READ.ME'
  190. fi
  191. if test -f 'convtab.1' -a "${1}" != "-c" ; then 
  192.   echo shar: Will not clobber existing file \"'convtab.1'\"
  193. else
  194. echo shar: Extracting \"'convtab.1'\" \(3120 characters\)
  195. sed "s/^X//" >'convtab.1' <<'END_OF_FILE'
  196. X.TH CONVTAB 1 "Feb 23, 1988"
  197. X.SH NAME
  198. Xconvtab \- convert nroff driver tables to ditroff form and vice-versa
  199. X.SH SYNOPSIS
  200. X.BR convtab " [ [" -vxd "] "
  201. X.IR files... "] ..."
  202. X.PP
  203. X.SH DESCRIPTION
  204. XThis tool may be used to convert nroff driver files between the all-ASCII form
  205. Xused by \fIditroff\fR(1) and the undocumented format used by old nroff. If
  206. Xcalled with no file arguments, it filters a ditroff file to old nroff form.
  207. X.PP
  208. XIf called with file arguments, it looks for a ``tab.'' prefix (denoting a
  209. Xditroff-format file) or (failing that) a ``tab'' prefix (denoting an
  210. Xnroff-format file). Each file mentioned on the command line is then
  211. Xconverted to a correspondingly-named file of the other form.
  212. X.PP
  213. XThe -v flag causes convtab to get chatty about what it's doing and what
  214. Xfiles it's converting. The -d flag forces -v and suppresses the actual
  215. Xfile conversions, so you can use it to verify what convtab would do with
  216. Xa given command line. Flags and filenames may be freely intermixed and
  217. Xare interpreted left to right on the command line.
  218. X.SH INCOMPATIBILITIES
  219. XNote that conversion from ditroff to nroff form may lose information, as
  220. Xnroff only allows redefinition of its ``wired-in'' escapes. Normally, if
  221. Xconvtab encounters an escape in a ditroff-format file than nroff doesn't
  222. Xhandle, it will emit a diagnostic and exit (but the -x flag allows it to
  223. Xcontinue in this case).
  224. X.PP
  225. XConversion from old nroff to ditroff files may also lose information, about
  226. Xwhat characters are allowed to be underlined for the .I highlight. Old-form
  227. Xdriver tables encoded this information in the high bit of each character's
  228. Xleading length byte. There is no documented way to include such information
  229. Xin the new format.
  230. X.PP
  231. XAlso, be aware that new nroff no longer assumes (as did older versions)
  232. Xthat the \fBtwnl\fR string turns off boldfacing. When converting old files
  233. Xto the new form, you may want to edit out any highlight-clearing string
  234. Xoccurring after \en in the \fBtwnl\fR entry.
  235. X.SH WARNING
  236. XBe aware that the new format's character-escape conventions are
  237. Xnot documented. It certainly accepts C-style three-digit-octal escapes and
  238. Xthe \eb, \en and \er escapes for backspace and newline (this much can be gleaned
  239. Xfrom looking at the driver files supplied with the system). The \et escape
  240. Xis therefore probably also good.
  241. X.PP
  242. XBut, for convenience in generating old-form driver tables from scratch,
  243. X.IR convtab (1)
  244. Xalso accepts two-digit hex escapes of the form \ex\fIdd\fR, and the special
  245. Xescape \ee for the ASCII ESC character (hex 0x1B).
  246. X.PP
  247. XWhen converting new-format files to old form, it might therefore be wise to
  248. Xcheck that these interpretations don't munch text that new nroff wants to see
  249. Xliterally. A quick way to verify this is to convert a copy of the old form to
  250. Xnew format again and diff the two new-format versions. If they differ, it's
  251. Xeither the result of a spurious escape or a bug (and if the latter, please
  252. Xreport it to the author!).
  253. X.SH AUTHOR
  254. XEric S. Raymond (...!rutgers!vu-vlsi!snark!eric) Feb 1988
  255. X.br
  256. XParts of this code are based on Bruce Townsend's table/elbat tools.
  257. X.SH SEE ALSO
  258. Xdotmatrix(1), term(5)
  259. END_OF_FILE
  260. if test 3120 -ne `wc -c <'convtab.1'`; then
  261.     echo shar: \"'convtab.1'\" unpacked with wrong size!
  262. fi
  263. # end of 'convtab.1'
  264. fi
  265. if test -f 'convtab.c' -a "${1}" != "-c" ; then 
  266.   echo shar: Will not clobber existing file \"'convtab.c'\"
  267. else
  268. echo shar: Extracting \"'convtab.c'\" \(3575 characters\)
  269. sed "s/^X//" >'convtab.c' <<'END_OF_FILE'
  270. X/*
  271. X * convtab.c -- convert old nroff driver tables to new form and vice-versa
  272. X *
  273. X * This main calls four functions dit{read,write} and ot{read,write} which seal
  274. X * away the operations of reading and writing new (dit*) and old (ot*) style
  275. X * nroff driver tables. All set up or read from the common nrtab_t structure.
  276. X *
  277. X * Common accesses to the structure are implemented in termtab.c, which
  278. X * contains code for a flavor of string storage pool that both use. The
  279. X * escapes.c module provides common character-escape and escape-expansion
  280. X * handling.
  281. X *
  282. X * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  283. X * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  284. X * freely, but don't try to make money selling it unless you're going to send
  285. X * me a cut. Send bug reports, love letters and death threats to eric@snark
  286. X * aka ...!rutgers!vu-vlsi!snark!eric.
  287. X */
  288. X/*LINTLIBRARY*/
  289. X#include <stdio.h>
  290. X#include "termtab.h"
  291. X
  292. Xextern char *mktemp(), *strcpy();
  293. Xextern void perror();
  294. X
  295. Xextern int ignorebad;    /* ditread.o supplies this */
  296. X
  297. Xmain(argc, argv)
  298. Xint argc;
  299. Xchar *argv[];
  300. X{
  301. X    int verbose = 0, debug = 0, filecount = 0;
  302. X    FILE *ifp, *ofp;
  303. X    nrtab_t *ttab;
  304. X    extern errno;
  305. X
  306. X    for (++argv, --argc; argc; argv++, argc--)
  307. X    {
  308. X    char sw = argv[0][0];
  309. X    char opt = argv[0][1];
  310. X
  311. X    if (sw == '-' || sw == '+')    /* a switch argument */
  312. X    {
  313. X        switch(opt)
  314. X        {
  315. X        case 'x':
  316. X        ignorebad = (sw == '-');
  317. X        if (verbose)
  318. X            (void) printf("convtab: ignorebad %s\n",
  319. X                  ignorebad ? "set" : "cleared");
  320. X        break;
  321. X
  322. X        case 'v':
  323. X        verbose = (sw == '-');
  324. X        if (verbose)
  325. X            (void) printf("convtab: verbose %s\n",
  326. X                  verbose ? "set" : "cleared");
  327. X        break;
  328. X
  329. X        case 'd':
  330. X        if (debug = (sw == '-'))
  331. X            verbose = 1;
  332. X        if (verbose)
  333. X            (void) printf("convtab: debug %s\n",
  334. X                  debug ? "set" : "cleared");
  335. X        break;
  336. X        }
  337. X    }
  338. X    else                /* a filename argument */
  339. X    {
  340. X        char target[BUFSIZ];
  341. X        char tempf[20];
  342. X
  343. X        filecount++;
  344. X
  345. X        (void) strcpy(tempf, "/tmp/convtabXXXXX");
  346. X        (void) mktemp(tempf);
  347. X
  348. X        if (strncmp(argv[0], "tab.", 4) == 0)
  349. X        {
  350. X        (void) sprintf(target, "tab%s", argv[0] + 4);
  351. X        if (verbose)
  352. X            (void) fprintf(stderr,
  353. X            "convtab: %s (ditroff format) to %s (old format)\n",
  354. X            argv[0], target);
  355. X        if (!debug)
  356. X        {
  357. X            ifp = fopen(argv[0], "r");
  358. X            ofp = fopen(tempf, "w");
  359. X
  360. X            ttab = ditread(ifp);
  361. X            otwrite(ttab, ofp);
  362. X
  363. X            if (unlink(target) == -1)
  364. X            perror("convtab (unlink failed)");
  365. X            if (link(tempf, target) == -1)
  366. X            perror("convtab (link failed)");
  367. X            if (unlink(tempf) == -1)
  368. X            perror("convtab (unlink failed)");
  369. X        }
  370. X        }
  371. X        else if (strncmp(argv[0], "tab", 3) == 0)
  372. X        {
  373. X        (void) sprintf(target, "tab.%s", argv[0] + 3);
  374. X        if (verbose)
  375. X            (void) fprintf(stderr,
  376. X            "convtab: %s (old format) to %s (ditroff format)\n",
  377. X            argv[0], target);
  378. X        if (!debug)
  379. X        {
  380. X            ifp = fopen(argv[0], "r");
  381. X            ofp = fopen(tempf, "w");
  382. X
  383. X            ttab = otread(ifp);
  384. X            (void) fprintf(ofp, "%s\n", target + 4);
  385. X            ditwrite(ttab, ofp);
  386. X
  387. X            if (unlink(target) == -1)
  388. X            perror("convtab (unlink failed)");
  389. X            if (link(tempf, target) == -1)
  390. X            perror("convtab (link failed)");
  391. X            if (unlink(tempf) == -1)
  392. X            perror("convtab (unlink failed)");
  393. X        }
  394. X        }
  395. X        else
  396. X        (void) fprintf(stderr,
  397. X               "convtab: skipping %s, (name prefix no good)\n",
  398. X               argv[0]);
  399. X    }
  400. X    }
  401. X
  402. X    /* no filenames given? that's OK, just convert new to old as a filter */
  403. X    if (filecount == 0)
  404. X    {
  405. X    ttab = ditread(ifp);
  406. X    otwrite(ttab, ofp);
  407. X    }
  408. X
  409. X    return(0);
  410. X}
  411. X
  412. X/* convtab.c ends here */
  413. END_OF_FILE
  414. if test 3575 -ne `wc -c <'convtab.c'`; then
  415.     echo shar: \"'convtab.c'\" unpacked with wrong size!
  416. fi
  417. # end of 'convtab.c'
  418. fi
  419. if test -f 'ditread.c' -a "${1}" != "-c" ; then 
  420.   echo shar: Will not clobber existing file \"'ditread.c'\"
  421. else
  422. echo shar: Extracting \"'ditread.c'\" \(6379 characters\)
  423. sed "s/^X//" >'ditread.c' <<'END_OF_FILE'
  424. X/*
  425. X * ditread.c -- read ditroff-format tables into internal form
  426. X *
  427. X * Use this function to read a ditroff-style all-ASCII driver table into the
  428. X * internal form given in the term.h header file.
  429. X *
  430. X * Standard C-style octal, hex and character escapes are accepted in string
  431. X * and character fields. Due to lack of documentation, I don't know whether
  432. X * {n,t}roff accepts hex escapes or character escape other than \[bnrt].
  433. X *
  434. X * The global ignorebad may be set to any nonzero value to cause this function
  435. X * to simply skip invalid ditroff characters (such as \(bx) rather than
  436. X * aborting when they are encountered. Otherwise, all errors emit a diagnostic
  437. X * to stderr and call exit(1).
  438. X *
  439. X * This code expects to be able to call an escape processor escape() to do
  440. X * its input character processing.
  441. X *
  442. X * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  443. X * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  444. X * freely, but don't try to make money selling it unless you're going to send
  445. X * me a cut. Send bug reports, love letters and death threats to eric@snark
  446. X * aka ...!rutgers!vu-vlsi!snark!eric.
  447. X */
  448. X/*LINTLIBRARY*/
  449. X#include <stdio.h>
  450. X#include <ctype.h>
  451. X#include "termtab.h"
  452. X
  453. Xextern char *strcpy(), *strchr(), *calloc();
  454. Xextern void exit();
  455. X
  456. X#define CTRL(c)    ((c) & 0x1F)
  457. X#define META    0x80
  458. X
  459. Xint ignorebad;    /* if nz, skip invalid character names instead of bombing */
  460. X
  461. Xstatic char buf[BUFSIZ];    /* common input buffer */
  462. X
  463. Xstatic char *digetstr(key, fp)
  464. X/* fill in the next string slot in the fixed-format part of the table */
  465. Xchar    *key;
  466. XFILE    *fp;
  467. X{
  468. X    char *lq, *rq;
  469. X
  470. X    (void) fgets(buf, BUFSIZ, fp);
  471. X    if (strncmp(buf, key, strlen(key)))
  472. X    {
  473. X    (void) fprintf(stderr, "tabconv: expected %s, saw %s", key, buf);
  474. X    exit(1);
  475. X    }
  476. X
  477. X    /* delimit the value string part */
  478. X    if ((lq = strchr(buf + strlen(key), '"')) == (char *)NULL)
  479. X    {
  480. X    (void) fprintf(stderr, "tabconv: missing leading quote at %s", buf);
  481. X    exit(1);
  482. X    }
  483. X    if ((rq = strchr(++lq, '"')) == (char *)NULL)
  484. X    {
  485. X    (void) fprintf(stderr, "tabconv: missing trailing quote at %s", buf);
  486. X    exit(1);
  487. X    }
  488. X    *rq = '\0';
  489. X    
  490. X    (void) escape(lq, lq);
  491. X    return(lq);
  492. X}
  493. X
  494. Xstatic void digetint(key, loc, fp)
  495. Xchar    *key;
  496. Xint    *loc;
  497. XFILE    *fp;
  498. X{
  499. X    (void) fgets(buf, BUFSIZ, fp);
  500. X    if (strncmp(buf, key, strlen(key)))
  501. X    {
  502. X    (void) fprintf(stderr, "tabconv: expected %s, saw %s", key, buf);
  503. X    exit(1);
  504. X    }
  505. X
  506. X    if (sscanf(buf + strlen(key), " %d", loc) != 1)
  507. X    {
  508. X    (void) fprintf(stderr, "tabconv: bad integer format at %s", buf);
  509. X    exit(1);
  510. X    }
  511. X}
  512. X
  513. Xstatic int digetchr(tp, fp)
  514. Xnrtab_t    *tp;
  515. XFILE    *fp;
  516. X{
  517. X    char charname[BUFSIZ], charval[BUFSIZ];
  518. X    register char **sp;
  519. X    int fc, width;
  520. X
  521. X    if (fgets(buf, BUFSIZ, fp) == (char *)NULL)
  522. X    return(EOF);
  523. X
  524. X    /* we must discard the width info, the old format doesn't support it */
  525. X    if ((fc = sscanf(buf, "%s %d %s", charname, &width, charval + 1)) != 3)
  526. X    {
  527. X    (void) fprintf(stderr,
  528. X        "tabconv: only %d fields found, bad char definition at %s",fc,buf);
  529. X    exit(1);
  530. X    }
  531. X
  532. X    /* find the referenced character name in the {n,t}roff name table */
  533. X    for (sp = ntnames; *sp != (char *)NULL; sp++)
  534. X    if (strcmp(*sp, charname) == 0)
  535. X        break;
  536. X    if (*sp == (char *)NULL)
  537. X    {
  538. X    (void) fprintf(stderr, "tabconv: bad character name at %s", buf);
  539. X    if (!ignorebad)
  540. X        exit(1);
  541. X    }
  542. X    else    /* character name found OK */
  543. X    {
  544. X    /* the hackery below is so we don't botch zero-width characters */
  545. X    if ((charval[0] = width) == 0)
  546. X        charval[0] |= META;
  547. X
  548. X    (void) escape(charval + 1, charval + 1);
  549. X    tp->codetab[sp - ntnames] = addstring(charval, &tp->pool);
  550. X
  551. X    if (width == 0)
  552. X        tp->codetab[sp - ntnames][0] &=~ META;
  553. X    }
  554. X    return(0);
  555. X}
  556. X
  557. Xnrtab_t *ditread(fp)
  558. X/* fill in a terminal table structure from a ditroff-format description */
  559. XFILE *fp;
  560. X{
  561. X    register char ch;
  562. X
  563. X#ifndef lint
  564. X    nrtab_t    *tp = (nrtab_t *) calloc(sizeof(nrtab_t), 1);
  565. X#else
  566. X    nrtab_t    *tp = (nrtab_t *)NULL;
  567. X#endif /* lint */
  568. X
  569. X    /* initialize the string table part of the malloc'd structure */
  570. X    (void) newstrings(&tp->pool);
  571. X
  572. X    /* read in the fixed-format part of the table first */
  573. X
  574. X    /* read name line */
  575. X    (void) fgets(buf, BUFSIZ, fp);
  576. X    buf[strlen(buf) - 1] = '\0';
  577. X    tp->name = addstring(buf, &tp->pool);
  578. X
  579. X    /* read integer printer parameters */
  580. X    digetint("bset", &tp->bset, fp);
  581. X    digetint("breset", &tp->breset, fp);
  582. X    digetint("Hor", &tp->Hor, fp);
  583. X    digetint("Vert", &tp->Vert, fp);
  584. X    digetint("Newline", &tp->Newline, fp);
  585. X    digetint("Char", &tp->Char, fp);
  586. X#ifdef KANJI
  587. X    digetint("Kchar", &tp->Kchar, fp);
  588. X#endif KANJI
  589. X    digetint("Em", &tp->Em, fp);
  590. X    digetint("Halfline", &tp->Halfline, fp);
  591. X    digetint("Adj", &tp->Adj, fp);
  592. X
  593. X    /* read string-valued parameters */
  594. X    tp->twinit    = addstring(digetstr("twinit", fp), &tp->pool);
  595. X    tp->twrest    = addstring(digetstr("twrest", fp), &tp->pool);
  596. X    tp->twnl    = addstring(digetstr("twnl", fp), &tp->pool);
  597. X    tp->hlr    = addstring(digetstr("hlr", fp), &tp->pool);
  598. X    tp->hlf    = addstring(digetstr("hlf", fp), &tp->pool);
  599. X    tp->flr    = addstring(digetstr("flr", fp), &tp->pool);
  600. X    tp->bdon    = addstring(digetstr("bdon", fp), &tp->pool);
  601. X    tp->bdoff    = addstring(digetstr("bdoff", fp), &tp->pool);
  602. X    tp->iton    = addstring(digetstr("iton", fp), &tp->pool);
  603. X    tp->itoff    = addstring(digetstr("itoff", fp), &tp->pool);
  604. X    tp->ploton    = addstring(digetstr("ploton", fp), &tp->pool);
  605. X    tp->plotoff = addstring(digetstr("plotoff", fp), &tp->pool);
  606. X    tp->up    = addstring(digetstr("up", fp), &tp->pool);
  607. X    tp->down    = addstring(digetstr("down", fp), &tp->pool);
  608. X    tp->right    = addstring(digetstr("right", fp), &tp->pool);
  609. X    tp->left    = addstring(digetstr("left", fp), &tp->pool);
  610. X
  611. X    /* skip blank line(s), then expect character set keyword */
  612. X    do {
  613. X        (void) fgets(buf, BUFSIZ, fp);
  614. X    } while
  615. X    (buf[0] == '\n');
  616. X    if (strcmp(buf, "charset\n"))
  617. X    {
  618. X    (void) fprintf(stderr, "tabconv: charset keyword missing\n");
  619. X    exit(1);
  620. X    }
  621. X
  622. X    /* insert defaults for printable characters */
  623. X    for (ch = CHARMIN; ch < CHARMAX && isprint(ch); ch++)
  624. X    {
  625. X    buf[0] = 1;                /* set default width */
  626. X    (void) strcpy(buf + 1, ntnames[ch - CHARMIN]);
  627. X    tp->codetab[ch-CHARMIN] = addstring(buf, &tp->pool);
  628. X    }
  629. X
  630. X    /* now read the character definitions */
  631. X    while (digetchr(tp, fp) != EOF)
  632. X    continue;
  633. X
  634. X    return(tp);
  635. X}
  636. X
  637. X/* ditread.c ends here */
  638. END_OF_FILE
  639. if test 6379 -ne `wc -c <'ditread.c'`; then
  640.     echo shar: \"'ditread.c'\" unpacked with wrong size!
  641. fi
  642. # end of 'ditread.c'
  643. fi
  644. if test -f 'ditwrite.c' -a "${1}" != "-c" ; then 
  645.   echo shar: Will not clobber existing file \"'ditwrite.c'\"
  646. else
  647. echo shar: Extracting \"'ditwrite.c'\" \(2818 characters\)
  648. sed "s/^X//" >'ditwrite.c' <<'END_OF_FILE'
  649. X/*
  650. X * ditwrite.c -- dump an internal driver-table representation in ditroff form
  651. X *
  652. X * Dumps a driver-table structure in all-ASCII ditroff format. Uses octal
  653. X * escape and \b, \t, \n, \r for nonprintable characters.
  654. X *
  655. X * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  656. X * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  657. X * freely, but don't try to make money selling it unless you're going to send
  658. X * me a cut. Send bug reports, love letters and death threats to eric@snark
  659. X * aka ...!rutgers!vu-vlsi!snark!eric.
  660. X */
  661. X/*LINTLIBRARY*/
  662. X#include <stdio.h>
  663. X#include <ctype.h>
  664. X#include "termtab.h"
  665. X
  666. Xstatic void tdump(fp, label, val)
  667. X/* dump a string (in quotes) with a given label prepended */
  668. XFILE *fp;
  669. Xchar *label;
  670. Xchar *val;
  671. X{
  672. X    if (val != (char *)NULL)
  673. X    {
  674. X    char outbuf[BUFSIZ];
  675. X
  676. X    (void) expand(val, outbuf);
  677. X    (void) fprintf(fp, "%-12s\"%s\"\n", outbuf, label);
  678. X    }
  679. X}
  680. X
  681. Xstatic void cdump(fp, label, width, val)
  682. X/* dump a character with its width */
  683. XFILE *fp;
  684. Xchar *label;
  685. Xint width;
  686. Xchar *val;
  687. X{
  688. X    if (val != (char *)NULL)
  689. X    {
  690. X    char outbuf[BUFSIZ];
  691. X
  692. X    (void) expand(val, outbuf);
  693. X    (void) fprintf(fp, "%s %d %s\n", outbuf, label, width);
  694. X    }
  695. X}
  696. X
  697. Xvoid ditwrite(tp, fp)
  698. Xnrtab_t *tp;
  699. XFILE    *fp;
  700. X{
  701. X    register char **ctab = tp->codetab;
  702. X
  703. X    /* first, dump integer parameters */
  704. X    (void) fprintf(fp, "bset        %d\n", tp->bset);
  705. X    (void) fprintf(fp, "breset      %d\n", tp->breset);
  706. X    (void) fprintf(fp, "Hor         %d\n", tp->Hor);
  707. X    (void) fprintf(fp, "Vert        %d\n", tp->Vert);
  708. X    (void) fprintf(fp, "Newline     %d\n", tp->Newline);
  709. X    (void) fprintf(fp, "Char        %d\n", tp->Char);
  710. X#ifdef KANJI
  711. X    (void) fprintf(fp, "Kchar        %d\n", tp->Kchar);
  712. X#endif KANJI
  713. X    (void) fprintf(fp, "Em          %d\n", tp->Em);
  714. X    (void) fprintf(fp, "Halfline    %d\n", tp->Halfline);
  715. X    (void) fprintf(fp, "Adj         %d\n", tp->Adj);
  716. X
  717. X    /* next, dump standard control strings */
  718. X    tdump(fp, "twinit", tp->twinit);
  719. X    tdump(fp, "twrest", tp->twrest);
  720. X    tdump(fp, "twnl", tp->twnl);
  721. X    tdump(fp, "hlr", tp->hlr);
  722. X    tdump(fp, "hlf", tp->hlf);
  723. X    tdump(fp, "flr", tp->flr);
  724. X    tdump(fp, "bdon", tp->bdon);
  725. X    tdump(fp, "bdoff", tp->bdoff);
  726. X    tdump(fp, "iton", tp->iton);
  727. X    tdump(fp, "itoff", tp->itoff);
  728. X    tdump(fp, "ploton", tp->ploton);
  729. X    tdump(fp, "plotoff", tp->plotoff);
  730. X    tdump(fp, "up", tp->up);
  731. X    tdump(fp, "down", tp->down);
  732. X    tdump(fp, "right", tp->right);
  733. X    tdump(fp, "left", tp->left);
  734. X
  735. X    /* finally, dump the character table */
  736. X    (void) fputs("\ncharset\n", fp);
  737. X    for (ctab = ntnames; ctab[0] != (char *)NULL; ctab++)
  738. X    {
  739. X    char *cstr = tp->codetab[ctab - ntnames];
  740. X
  741. X    if ((cstr[0] || cstr[1]) && strcmp(ctab[0], cstr + 1))
  742. X        cdump(fp, ctab[0], cstr[0], cstr + 1);
  743. X    }
  744. X}
  745. X
  746. X/* ditwrite.c ends here */
  747. END_OF_FILE
  748. if test 2818 -ne `wc -c <'ditwrite.c'`; then
  749.     echo shar: \"'ditwrite.c'\" unpacked with wrong size!
  750. fi
  751. # end of 'ditwrite.c'
  752. fi
  753. if test -f 'dotmatrix.1' -a "${1}" != "-c" ; then 
  754.   echo shar: Will not clobber existing file \"'dotmatrix.1'\"
  755. else
  756. echo shar: Extracting \"'dotmatrix.1'\" \(4836 characters\)
  757. sed "s/^X//" >'dotmatrix.1' <<'END_OF_FILE'
  758. X.TH DOTMATRIX 1 "Feb 23, 1988"
  759. X.SH NAME
  760. Xdotmatrix \- make driver table and postprocessor for dot-matrix printer
  761. X.SH SYNOPSIS
  762. X.BR dotmatrix
  763. X[
  764. X.IR -nvtpdq " ] [ " postprocessor-name " ]"
  765. X.PP
  766. X.SH DESCRIPTION
  767. XThis utility interprets a file containing various directives specifying
  768. Xcharacter set graphics, highlight sequences, and the like. By default, it
  769. Xproduces as output the following files:
  770. X.TP 10
  771. Xtab.mx80
  772. Xa ditroff-format driver file
  773. X.TP 10
  774. Xmx80.c
  775. Xa postprocessor for use with nroff
  776. X.TP 10
  777. Xmx80.test 
  778. Xa test file that exercises the driver and postprocessor.
  779. X.PP
  780. XIf a command line argument is given, it is taken as the name for the generated
  781. Xpostprocessor and substituted for the `mx80' in the default names above.
  782. X.PP
  783. XThe directives file format is all-ASCII, line oriented, and similar to that of
  784. Xa ditroff table. In fact, everything up to and including a line reading
  785. X`charset' is passed through unaltered to the driver table (except that comments
  786. Xbeginning with # are stripped out).
  787. X.PP
  788. XFollowing the charset directive, the normal character set table is replaced by
  789. Xa sequence of \fBcomment\fR, \fBmode\fR, \fBtoggle\fR, \fBoverstrike\fR and
  790. X\fBpicture\fR directives.
  791. XComments beginning with # may be present anywhere but in the body of
  792. Xa picture section and will be discarded (except that comments trailing a
  793. X\fBpicture\fR directive are include in the appropriate place in the generated
  794. Xtest file).
  795. X.PP
  796. XThe directives are as follows:
  797. X.SS
  798. X\fBcomment\fR <text>
  799. XText following a comment directive is embedded in a comment in the generated
  800. Xpostprocessor source. It is recommended that you use this feature to identify
  801. Xthe font and its author and explain any special features it may have.
  802. X.SS
  803. X\fBmode\fR <name> <height> <format>
  804. X.PP
  805. XDeclares a print mode. The first argument must be a mode name of 10 or fewer
  806. Xletters. The second must be a decimal numeric height in pixels. The third must
  807. Xbe a printf-style string with the following escapes defined:
  808. X.IP
  809. X.TP
  810. X%h
  811. Xhigh byte of graphic length in pixels
  812. X.TP
  813. X%l
  814. Xlow byte of graphic length in pixels
  815. X.TP
  816. X%c
  817. Xgraphic raster by column, leftmost column first
  818. X.RE
  819. XAll normal C-style escapes and the \\e convention for ESC are also accepted.
  820. X.SS
  821. X\fBtoggle\fR <escape> <on> <off>
  822. X.PP
  823. XDeclares a given escape to be a toggle in the postprocessor, and gives the
  824. Xtwo on and off strings that will implement it.
  825. X.SS
  826. X\fBoverstrike\fR <escape> <char>
  827. X.PP
  828. XDeclares a given escape to be an overstrike toggle in the postprocessor, and
  829. Xgives the overstrike character to use.
  830. X.SS
  831. X\fBpicture\fR <name> <em-width> <mode> <width>
  832. X.PP
  833. XThe \fBpicture\fR directive takes four arguments. The first is the nroff
  834. Xescape name, the second is the picture's width in ems. The third must match
  835. Xa declared mode, and the fourth should be a decimal numeric width.
  836. X.PP
  837. XEach picture directive must be followed by an 8-line bit image for the escape.
  838. XAsterisk characters will be read as `on'. Trailing non-asterisks designating
  839. Xbits off may be omitted.
  840. X.PP
  841. XThe -n option prevents \fIdotmatrix\fR(1) from trying to put any knowledge of 
  842. Xthe printer into the driver; only standard escapes for the generated
  843. Xpostprocessor will be generated (see the NOTE below).
  844. X.PP
  845. XThe -v option causes the program to echo each input line along with remarks
  846. Xabout how it's being processed. The -q option makes the program extra quiet,
  847. Xsuppressing normal messages about which special characters and highlights
  848. Xneed to be handled in the postprocessor and which will be emitted through the
  849. Xdriver table alone.
  850. X.PP
  851. XThe -t, -p and -d options suppress creation of the test,
  852. Xpostprocessor source and driver table files respectively.
  853. X.PP
  854. XWhen creating new picture files, it is recommended that you start from an
  855. Xexisting file and modify it, rather than starting from scratch.
  856. X.SH DIAGNOSTICS
  857. XVarious self-explanatory diagnostics may be emitted to stderr. 0 is returned
  858. Xfrom a correct run, 1 if a parse error terminated translation of the input
  859. Xfile, 2 if some output file could not be opened.
  860. X.SH FILES
  861. X.TP 12
  862. Xpost.proto
  863. Xprototype C code for the printer-specific postprocessor
  864. X.SH NOTE
  865. XNroff barfs on nuls in escape strings. This is what makes the postprocessor
  866. Xnecessary. In place of escapes that would include nuls, the generated driver
  867. Xtable will emit strings to the postprocessor of the form SI + <char> + SO (so
  868. Xthey'll pass through \fIcol\fR(1) correctly without the -p option).
  869. X.PP
  870. XIf you use col, <data> must be printable; this effectively limits you to
  871. Xat most 96 escapes containing NULs (though \fIdotmatrix\fR(1) will generate
  872. Xescapes with <char> 128 to 255 without complaining). Using col probably also
  873. Xmeans you want to use a driver table generated with the the -n option, to
  874. Xforce all the nonprintable-character emission into the postprocessor.
  875. X.SH AUTHOR
  876. XEric S. Raymond (...!rutgers!vu-vlsi!snark!eric) Feb 1988
  877. X.SH SEE ALSO
  878. Xconvtab(1), term(5)
  879. END_OF_FILE
  880. if test 4836 -ne `wc -c <'dotmatrix.1'`; then
  881.     echo shar: \"'dotmatrix.1'\" unpacked with wrong size!
  882. fi
  883. # end of 'dotmatrix.1'
  884. fi
  885. if test -f 'escapes.c' -a "${1}" != "-c" ; then 
  886.   echo shar: Will not clobber existing file \"'escapes.c'\"
  887. else
  888. echo shar: Extracting \"'escapes.c'\" \(2229 characters\)
  889. sed "s/^X//" >'escapes.c' <<'END_OF_FILE'
  890. X/*
  891. X * escape.c -- interpret and expand character escapes
  892. X *
  893. X * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  894. X * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  895. X * freely, but don't try to make money selling it unless you're going to send
  896. X * me a cut. Send bug reports, love letters and death threats to eric@snark
  897. X * aka ...!rutgers!vu-vlsi!snark!eric.
  898. X */
  899. X/*LINTLIBRARY*/
  900. X#include <stdio.h>
  901. X#include <ctype.h>
  902. X
  903. Xint escape(cp, tp)
  904. X/* interpret standard C-style octal and hex escapes plus \e for ESC */
  905. Xchar    *cp, *tp;
  906. X{
  907. X    extern char *strchr();
  908. X    int ccount = 0;
  909. X
  910. X    while (*cp)
  911. X    {
  912. X    int    cval = 0;
  913. X
  914. X    if (*cp == '\\' && strchr("0123456789xX", cp[1]))
  915. X    {
  916. X        char *dp, *hex = "00112233445566778899aAbBcCdDeEfF";
  917. X        int dcount = 0;
  918. X
  919. X        if (*++cp == 'x' || *cp == 'X')
  920. X        for (++cp; (dp = strchr(hex, *cp)) && dcount++ < 2; cp++)
  921. X            cval = (cval * 16) + (dp - hex) / 2;
  922. X        else if (*cp == '0')
  923. X        while (strchr("01234567", *cp) && dcount++ < 3)
  924. X            cval = (cval * 8) + (*cp++ - '0');
  925. X        else
  926. X        while (strchr("0123456789", *cp) && dcount++ < 3)
  927. X            cval = (cval * 10) + (*cp++ - '0');
  928. X    }
  929. X    else if (*cp == '\\')        /* C-style character escape */
  930. X    {
  931. X        switch (*++cp)
  932. X        {
  933. X        case '\\': cval = '\\'; break;
  934. X        case 'n': cval = '\n'; break;
  935. X        case 't': cval = '\t'; break;
  936. X        case 'b': cval = '\b'; break;
  937. X        case 'r': cval = '\r'; break;
  938. X        case 'e': cval = 0x1b; break;
  939. X        default: cval = *cp;
  940. X        }
  941. X        cp++;
  942. X    }
  943. X    else
  944. X        cval = *cp++;
  945. X    *tp++ = cval;
  946. X    ccount++;
  947. X    }
  948. X    *tp = '\0';
  949. X    return(ccount);
  950. X}
  951. X
  952. Xint expand(sp, tp)
  953. X/* generate a restricted set of escapes for nonprintable chars in a string */
  954. Xchar *sp;
  955. Xchar *tp;
  956. X{
  957. X    char *start;
  958. X
  959. X    for (start = tp; *sp; sp++)
  960. X    {
  961. X    if (!isprint(*sp) || *sp == '\\')
  962. X        *tp++ = '\\';
  963. X
  964. X    if (*sp == '\\')
  965. X        *tp++ = '\\';
  966. X    else if (*sp == '\b')
  967. X        *tp++ = '\b';
  968. X    else if (*sp == '\n')
  969. X        *tp++ = '\n';
  970. X    else if (*sp == '\t')
  971. X        *tp++ = '\t';
  972. X    else if (*sp == '\r')
  973. X        *tp++ = '\r';
  974. X    else if (isprint(*sp))
  975. X        *tp++ = *sp;
  976. X    else
  977. X    {
  978. X        (void) sprintf(tp, "\\%03.3o", toascii(*sp));
  979. X        tp += strlen(tp);
  980. X    }
  981. X    }
  982. X    *tp = '\0';
  983. X    return(tp - start);
  984. X}
  985. X
  986. X/* escape.c ends here */
  987. END_OF_FILE
  988. if test 2229 -ne `wc -c <'escapes.c'`; then
  989.     echo shar: \"'escapes.c'\" unpacked with wrong size!
  990. fi
  991. # end of 'escapes.c'
  992. fi
  993. if test -f 'otread.c' -a "${1}" != "-c" ; then 
  994.   echo shar: Will not clobber existing file \"'otread.c'\"
  995. else
  996. echo shar: Extracting \"'otread.c'\" \(2820 characters\)
  997. sed "s/^X//" >'otread.c' <<'END_OF_FILE'
  998. X/*
  999. X * otread.c -- read a driver table in old nroff format into core
  1000. X *
  1001. X * Use this function to read an old-nroff-style driver table into the
  1002. X * internal form given in the term.h header file. Note that the terminal
  1003. X * name slot is *not* filled in.
  1004. X *
  1005. X * This function will return NULL if the input file is too short (i.e its
  1006. X * length is less than sizeof(int) + sizeof(t_stor) + the byte count
  1007. X * in the file's first int). It will also return NULL if it finds an offset
  1008. X * larger than the string table size.
  1009. X *
  1010. X * Warning: the driver structure pointer handed back uses static storage,
  1011. X * a second otread() call will overwrite it.
  1012. X *
  1013. X * Also, the code performs mildly unnatural acts on some structure fields.
  1014. X * See the last comment before the end of the routine and beware. If the
  1015. X * method fails it's more than likely to result in garbaged pointers in the
  1016. X * returned internal-representation structure and core dumps later on.
  1017. X *
  1018. X * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  1019. X * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  1020. X * freely, but don't try to make money selling it unless you're going to send
  1021. X * me a cut. Send bug reports, love letters and death threats to eric@snark
  1022. X * aka ...!rutgers!vu-vlsi!snark!eric.
  1023. X */
  1024. X/*LINTLIBRARY*/
  1025. X#include <stdio.h>
  1026. X#include "termtab.h"
  1027. X
  1028. Xextern char *malloc();
  1029. X
  1030. Xnrtab_t *otread(tfp)
  1031. XFILE *tfp;
  1032. X{
  1033. X    int        c_size, *ip;
  1034. X    register char    **pp, *mptr;
  1035. X    static nrext_t    external;
  1036. X    static nrtab_t    internal;
  1037. X
  1038. X    /* string table size */
  1039. X    if (fread((char *)&c_size, sizeof(int), 1, tfp) != 1)
  1040. X    return((nrtab_t *)NULL);
  1041. X
  1042. X    /* fixed-size header part */
  1043. X    if (fread((char *)&external, sizeof(external), 1, tfp) != 1)
  1044. X    return((nrtab_t *)NULL);
  1045. X
  1046. X    /* now read the strings table into core */
  1047. X    if (fread(mptr = malloc((unsigned)c_size), c_size, 1, tfp) != 1)
  1048. X    return((nrtab_t *)NULL);
  1049. X
  1050. X    internal.bset = external.bset;
  1051. X    internal.breset = external.breset;
  1052. X    internal.Hor = external.Hor;
  1053. X    internal.Vert = external.Vert;
  1054. X    internal.Newline = external.Newline;
  1055. X    internal.Char = external.Char;
  1056. X    internal.Em = external.Em;
  1057. X    internal.Halfline = external.Halfline;
  1058. X    internal.Adj = external.Adj;
  1059. X
  1060. X    /*
  1061. X     * Wooo-ah! Tricky-shit alert! We step through the fields of the external
  1062. X     * and internal representation structures as though they were arrays of
  1063. X     * (int) and (char *) respectively. C's structure-padding rules *seem*
  1064. X     * to almost guarantee this will work, but I wouldn't bet the farm on it
  1065. X     * given some of the weird broken architectures and compilers out there.
  1066. X     */
  1067. X    for (ip = &external.twinit, pp = &internal.twinit; pp < &internal.zzz; )
  1068. X    if (*ip > c_size)
  1069. X        return((nrtab_t *)NULL);
  1070. X    else
  1071. X        *pp++ = mptr + *ip++;
  1072. X
  1073. X    return(&internal);
  1074. X}
  1075. X
  1076. X/* otread.c ends here */
  1077. END_OF_FILE
  1078. if test 2820 -ne `wc -c <'otread.c'`; then
  1079.     echo shar: \"'otread.c'\" unpacked with wrong size!
  1080. fi
  1081. # end of 'otread.c'
  1082. fi
  1083. if test -f 'otwrite.c' -a "${1}" != "-c" ; then 
  1084.   echo shar: Will not clobber existing file \"'otwrite.c'\"
  1085. else
  1086. echo shar: Extracting \"'otwrite.c'\" \(6014 characters\)
  1087. sed "s/^X//" >'otwrite.c' <<'END_OF_FILE'
  1088. X/*
  1089. X * otwrite.c -- dump an internal driver-table representation in old-nroff form
  1090. X *
  1091. X * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  1092. X * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  1093. X * freely, but don't try to make money selling it unless you're going to send
  1094. X * me a cut. Send bug reports, love letters and death threats to eric@snark
  1095. X * aka ...!rutgers!vu-vlsi!snark!eric.
  1096. X *
  1097. X * This stuff was Bruce Townsend & Ian Darwin's table.c code in a former life,
  1098. X * but the data structures are different and cleaner now.
  1099. X */
  1100. X/*LINTLIBRARY*/
  1101. X#include <stdio.h>
  1102. X#include "termtab.h"
  1103. X
  1104. Xextern char *strcpy();
  1105. Xextern void exit();
  1106. X
  1107. Xstatic void addchar(string, pp)
  1108. Xchar    *string;
  1109. Xstrtab    *pp;
  1110. X{
  1111. X    pp->c_pointer[pp->n_strings] = pp->c_end;
  1112. X    pp->c_end += (pp->c_length[pp->n_strings] = strlen(string + 2) + 2) + 1;
  1113. X    if (pp->c_end >= pp->c_data + C_SIZE)
  1114. X    {
  1115. X    (void) fprintf(stderr, "Table size too small, increase it!\n");
  1116. X    exit(1);
  1117. X    }
  1118. X    /*
  1119. X     * copy in the first two bytes without checking for a NUL, this is
  1120. X     * so we handle the (legal!) case of 0-length characters correctly
  1121. X     */
  1122. X    *pp->c_pointer[pp->n_strings] = *string++;
  1123. X    *(pp->c_pointer[pp->n_strings]+1) = *string++;
  1124. X
  1125. X     /* now copy the rest */
  1126. X    (void) strcpy(pp->c_pointer[pp->n_strings++] + 2, string);
  1127. X}
  1128. X
  1129. Xstatic int findchar(string, pp)
  1130. Xstrtab    *pp;
  1131. Xchar    *string;
  1132. X{
  1133. X    int    c_len, s_len, i;
  1134. X
  1135. X    for (i = 0; i < pp->n_strings; i++)
  1136. X    {
  1137. X    if ((c_len = pp->c_length[i]) >= (s_len = strlen (string+2) + 2))
  1138. X    {
  1139. X        if (!char_comp (string, pp->c_pointer[i] + c_len - s_len, s_len))
  1140. X        return (pp->c_pointer[i] + c_len - s_len - pp->c_data);
  1141. X    }
  1142. X    }
  1143. X    (void) fprintf(stderr,
  1144. X           "Serious bug! character %s not found in table\n", string);
  1145. X    exit(1);
  1146. X    /* NOTREACHED */
  1147. X}
  1148. X
  1149. Xstatic void write_err()
  1150. X{
  1151. X    (void) fprintf(stderr, "Write to file failed\n");
  1152. X    exit(1);
  1153. X}
  1154. X
  1155. Xvoid otwrite(tp, fp)
  1156. Xnrtab_t *tp;
  1157. XFILE    *fp;
  1158. X{
  1159. X    int    i, j, i_len, j_len, ch;
  1160. X    char    *tail, *start, *char_pointer;
  1161. X    static nrext_t t_stor;
  1162. X    static strtab otab;
  1163. X
  1164. X    newstrings(&otab);
  1165. X
  1166. X    /*
  1167. X     * copy the integer values from the initialized structure
  1168. X     * to the storage structure
  1169. X     */
  1170. X    t_stor.bset = tp->bset;
  1171. X    t_stor.breset = tp->breset;
  1172. X    t_stor.Hor = tp->Hor;
  1173. X    t_stor.Vert = tp->Vert;
  1174. X    t_stor.Newline = tp->Newline;
  1175. X    t_stor.Char = tp->Char;
  1176. X    t_stor.Em = tp->Em;
  1177. X    t_stor.Halfline = tp->Halfline;
  1178. X    t_stor.Adj = tp->Adj;
  1179. X
  1180. X    /*
  1181. X     * force an empty string with a 0-length head character to exist
  1182. X     * at offset 0 of the otab string table
  1183. X     */
  1184. X    (void) addchar("\000\000", &otab);
  1185. X
  1186. X    /*
  1187. X     * copy control strings out of the in-core form into the otab string table
  1188. X     */
  1189. X    (void) addstring(tp->twinit, &otab);
  1190. X    (void) addstring(tp->twrest, &otab);
  1191. X    (void) addstring(tp->twnl, &otab);
  1192. X    (void) addstring(tp->hlr, &otab);
  1193. X    (void) addstring(tp->hlf, &otab);
  1194. X    (void) addstring(tp->flr, &otab);
  1195. X    (void) addstring(tp->bdon, &otab);
  1196. X    (void) addstring(tp->bdoff, &otab);
  1197. X    (void) addstring(tp->iton, &otab);
  1198. X    (void) addstring(tp->itoff, &otab);
  1199. X    (void) addstring(tp->ploton, &otab);
  1200. X    (void) addstring(tp->plotoff, &otab);
  1201. X    (void) addstring(tp->up, &otab);
  1202. X    (void) addstring(tp->down, &otab);
  1203. X    (void) addstring(tp->right, &otab);
  1204. X    (void) addstring(tp->left, &otab);
  1205. X
  1206. X    /* copy character expansions to the new table */
  1207. X    for (ch = CHARMIN; ch < CHARMAX; ch++)
  1208. X    if (tp->codetab[ch - CHARMIN] != (char *)NULL)
  1209. X        addchar(tp->codetab[ch - CHARMIN], &otab);
  1210. X
  1211. X    /* eliminate strings which are tails of other strings */
  1212. X    for (i = 0; i < otab.n_strings; i++)
  1213. X    {
  1214. X    if (!otab.c_pointer[i])
  1215. X        continue;    /* String cleared out */
  1216. X    i_len = otab.c_length[i];
  1217. X    for (j = 0; j < otab.n_strings; j++)
  1218. X    {
  1219. X        if (i == j || ! otab.c_pointer[j]) continue;
  1220. X        j_len = otab.c_length[j];
  1221. X        if (i_len <= j_len)    /* string i could be tail of string j */
  1222. X        {
  1223. X        tail = otab.c_pointer[j] + j_len - i_len;
  1224. X        if (! char_comp(otab.c_pointer[i], tail, i_len)) {
  1225. X            otab.c_pointer[i] = 0;
  1226. X            break;
  1227. X        }
  1228. X        }
  1229. X    }
  1230. X    }
  1231. X
  1232. X    /* Compress the otab.c_data array */
  1233. X    char_pointer = otab.c_data;
  1234. X    for (i = j = 0; i < otab.n_strings; i++)
  1235. X    {
  1236. X    if (! (start = otab.c_pointer[i]))
  1237. X        continue;
  1238. X    otab.c_pointer[j] = char_pointer;
  1239. X    otab.c_length[j++] = otab.c_length[i];
  1240. X    for (i_len = otab.c_length[i]; i_len--;)
  1241. X        *char_pointer++ = *start++;
  1242. X    *char_pointer++ = 0;
  1243. X    }
  1244. X    otab.n_strings = j;
  1245. X    otab.c_size = char_pointer - otab.c_data;
  1246. X
  1247. X    /* Now find each string in this table and provide an index to it */
  1248. X    t_stor.twinit = findstring(tp->twinit, &otab);
  1249. X    t_stor.twrest = findstring(tp->twrest, &otab);
  1250. X    t_stor.twnl = findstring(tp->twnl, &otab);
  1251. X    t_stor.hlr = findstring(tp->hlr, &otab);
  1252. X    t_stor.hlf = findstring(tp->hlf, &otab);
  1253. X    t_stor.flr = findstring(tp->flr, &otab);
  1254. X    t_stor.bdon = findstring(tp->bdon, &otab);
  1255. X    t_stor.bdoff = findstring(tp->bdoff, &otab);
  1256. X    t_stor.iton = findstring(tp->iton, &otab);
  1257. X    t_stor.itoff = findstring(tp->itoff, &otab);
  1258. X    t_stor.ploton = findstring(tp->ploton, &otab);
  1259. X    t_stor.plotoff = findstring(tp->plotoff, &otab);
  1260. X    t_stor.up = findstring(tp->up, &otab);
  1261. X    t_stor.down = findstring(tp->down, &otab);
  1262. X    t_stor.right = findstring(tp->right, &otab);
  1263. X    t_stor.left = findstring(tp->left, &otab);
  1264. X
  1265. X    for (ch = CHARMIN; ch < CHARMAX; ch++)
  1266. X    if (tp->codetab[ch-CHARMIN] == (char *)NULL)
  1267. X        t_stor.codetab[ch-CHARMIN] = 0;    /* empty expansion */
  1268. X    else
  1269. X        t_stor.codetab[ch-CHARMIN]=findchar(tp->codetab[ch-CHARMIN],&otab);
  1270. X
  1271. X    t_stor.zzz = 0;
  1272. X
  1273. X    /* Write the character storage block size */
  1274. X    if (fwrite((char *)&otab.c_size, sizeof(otab.c_size), 1, fp) != 1)
  1275. X    write_err();
  1276. X
  1277. X    /* now the fixed part */
  1278. X    if (fwrite(&t_stor, sizeof(t_stor), 1, fp) != 1)
  1279. X    write_err();
  1280. X
  1281. X    /* finally, write the code table */
  1282. X    if (fwrite(otab.c_data,sizeof(*otab.c_data),otab.c_size,fp) != otab.c_size)
  1283. X    write_err();
  1284. X}
  1285. X
  1286. X/* otwrite.c ends here */
  1287. END_OF_FILE
  1288. if test 6014 -ne `wc -c <'otwrite.c'`; then
  1289.     echo shar: \"'otwrite.c'\" unpacked with wrong size!
  1290. fi
  1291. # end of 'otwrite.c'
  1292. fi
  1293. if test -f 'post.proto' -a "${1}" != "-c" ; then 
  1294.   echo shar: Will not clobber existing file \"'post.proto'\"
  1295. else
  1296. echo shar: Extracting \"'post.proto'\" \(1671 characters\)
  1297. sed "s/^X//" >'post.proto' <<'END_OF_FILE'
  1298. X
  1299. X#include <stdio.h>
  1300. X#include <ctype.h>
  1301. X
  1302. X#define MGL    64    /* maximum number of columns in a graphic */
  1303. X#define BS    010    /* ASCII backspace (for overstrikes) */
  1304. X#define SI    0x17    /* ASCII SI starts a graphics escape */
  1305. X#define SO    0x16    /* ASCII SO ends a graphics escape */
  1306. X
  1307. Xstatic char    overc = ' ';
  1308. X
  1309. Xstruct xlat
  1310. X{
  1311. X    int     tstate;    /* -1 if normal, 0 if this one, 1 if next */
  1312. X    int        len;    /* count of bytes in the graphic */
  1313. X    char    bytes[MGL];    /* tme actual bytes of the graphic */
  1314. X}
  1315. Xgraphic[] =
  1316. X{
  1317. X$A    /***** GRAPHIC TABLE GOES HERE *****/
  1318. X};
  1319. X
  1320. Xmain()
  1321. X{
  1322. X    register int    c, i, j;
  1323. X
  1324. X    while ((c = getchar()) != EOF)
  1325. X    {
  1326. X    if (c == SI)    /* a graphic or overstrike change */
  1327. X    {
  1328. X        /* check that the key character is in range */
  1329. X        if ((c = getchar()) && c >= ' ' && c < MAXSPCH)
  1330. X        {
  1331. X        register struct xlat *gr = &graphic[c - ' '];
  1332. X
  1333. X        /* this is the logic for doing toggle pairs */
  1334. X        switch (gr->tstate)
  1335. X        {
  1336. X        case -1:    /* the character isn't a toggle */
  1337. X            break;
  1338. X
  1339. X        case 0:        /* print start string */
  1340. X            gr->tstate = 1;
  1341. X            break;
  1342. X
  1343. X        case 1:        /* print end string */
  1344. X            gr->tstate = 0;
  1345. X            gr++;
  1346. X            break;
  1347. X
  1348. X        case 2:        /* change overstrike */
  1349. X            if (overc == gr->bytes[0])
  1350. X            overc = ' ';
  1351. X            else
  1352. X            overc = gr->bytes[0];
  1353. X            continue;    /* don't want to emit a graphic */
  1354. X        }
  1355. X
  1356. X        /* now emit the bytes of the adjusted character */
  1357. X        for (j = 0; j < gr->len; j++)
  1358. X            putchar(gr->bytes[j]);
  1359. X        }
  1360. X    }
  1361. X    else if (c == SO)        /* this appeases col(1) */ 
  1362. X        continue;
  1363. X    else if (!isspace(overc))    /* overstrike is enabled */
  1364. X    {
  1365. X        putchar(overc);
  1366. X        putchar(BS);
  1367. X        putchar(c);
  1368. X    }
  1369. X    else                /* ordinary character */
  1370. X        putchar(c);
  1371. X    }
  1372. X}
  1373. X
  1374. END_OF_FILE
  1375. if test 1671 -ne `wc -c <'post.proto'`; then
  1376.     echo shar: \"'post.proto'\" unpacked with wrong size!
  1377. fi
  1378. # end of 'post.proto'
  1379. fi
  1380. if test -f 'term.5' -a "${1}" != "-c" ; then 
  1381.   echo shar: Will not clobber existing file \"'term.5'\"
  1382. else
  1383. echo shar: Extracting \"'term.5'\" \(6726 characters\)
  1384. sed "s/^X//" >'term.5' <<'END_OF_FILE'
  1385. X.TH TERM 5
  1386. X.SH NAME
  1387. Xterm \- terminal driving tables for nroff (old format)
  1388. X.SH DESCRIPTION
  1389. XNote: if you have AT&T System Vr3 or are using the enhanced DWB software
  1390. Xwith
  1391. X.IR ditroff (1),
  1392. Xthis manual page will probably just mislead you! Your nroff driver files now
  1393. Xlive in /usr/lib/nterm in an all-ASCII format that should be documented as
  1394. X.IR nterm (5)
  1395. Xin your manuals.
  1396. X.PP
  1397. X.IR Nroff (1)
  1398. Xuses driving tables to customize its output for various types of
  1399. Xoutput devices, such as printing terminals, special word-processing
  1400. Xterminals (such as Diablo, Qume, or NEC Spinwriter mechanisms),
  1401. Xor special output filter programs.  These driving tables are written
  1402. Xas C programs, compiled, and installed in
  1403. X\f3/usr/lib/term/tab\f2name\fP ,
  1404. Xwhere
  1405. X.I name\^
  1406. Xis the name for that terminal type as given in
  1407. X.IR term (7).
  1408. XThe structure of the tables is as follows:
  1409. X.PP
  1410. X.nf
  1411. X.ta 5m 10m 15m 20m 25m 30m 35m 40m 45m 50m 55m 60m
  1412. X#define    INCH    240
  1413. X
  1414. Xstruct {
  1415. X    int bset;
  1416. X    int breset;
  1417. X    int Hor;
  1418. X    int Vert;
  1419. X    int Newline;
  1420. X    int Char;
  1421. X    int Em;
  1422. X    int Halfline;
  1423. X    int Adj;
  1424. X    char *twinit;
  1425. X    char *twrest;
  1426. X    char *twnl;
  1427. X    char *hlr;
  1428. X    char *hlf;
  1429. X    char *flr;
  1430. X    char *bdon;
  1431. X    char *bdoff;
  1432. X    char *iton;
  1433. X    char *itoff;
  1434. X    char *ploton;
  1435. X    char *plotoff;
  1436. X    char *up;
  1437. X    char *down;
  1438. X    char *right;
  1439. X    char *left;
  1440. X    char *codetab[256\-32];
  1441. X    char *zzz;
  1442. X} t;
  1443. X.fi
  1444. X.DT
  1445. X.PP
  1446. XThe meanings of the various fields are as follows:
  1447. X.TP 10
  1448. X.I bset\^
  1449. Xbits to set in the
  1450. X.I c_oflag\^
  1451. Xfield of the
  1452. X.I termio\^
  1453. Xstructure (see
  1454. X.IR tty (4))
  1455. Xbefore output.
  1456. X.TP 10
  1457. X.I breset\^
  1458. Xbits to reset in the
  1459. X.I c_oflag\^
  1460. Xfield of the
  1461. X.I termio\^
  1462. Xstructure
  1463. Xbefore output.
  1464. X.TP 10
  1465. X.I Hor\^
  1466. Xhorizontal resolution in fractions of an inch.
  1467. X.TP 10
  1468. X.I Vert\^
  1469. Xvertical resolution in fractions of an inch.
  1470. X.TP 10
  1471. X.I Newline\^
  1472. Xspace moved by a newline (linefeed) character in fractions
  1473. Xof an inch.
  1474. X.TP 10
  1475. X.I Char\^
  1476. Xquantum of character sizes, in fractions of an inch.
  1477. X(i.e., a character is a multiple of Char units wide)
  1478. X.TP 10
  1479. X.I Kchar\^
  1480. Xquantum of Kanji character sizes, in fractions of an inch.
  1481. X(i.e., a Kanji character is a multiple of Kchar units wide)
  1482. XMany systems do not have this element included in the structure.
  1483. X.TP 10
  1484. X.I Em\^
  1485. Xsize of an em in fractions of an inch.
  1486. X.TP 10
  1487. X.I Halfline\^
  1488. Xspace moved by a half-linefeed (or half-reverse-linefeed)
  1489. Xcharacter in fractions of an inch.
  1490. X.TP 10
  1491. X.I Adj\^
  1492. Xquantum of white space, in fractions of an inch.
  1493. X(i.e., white spaces are a multiple of Adj units wide)
  1494. X.IP
  1495. XNote: if this is less than the size of the space
  1496. Xcharacter (in units of Char; see below for how the
  1497. Xsizes of characters are defined),
  1498. X.I nroff\^
  1499. Xwill output
  1500. Xfractional spaces using plot mode.  Also, if the
  1501. X.B \-e
  1502. Xswitch to
  1503. X.I nroff\^
  1504. Xis used, Adj is set equal to Hor by
  1505. X.IR nroff .
  1506. X.TP 10
  1507. X.I twinit\^
  1508. Xset of characters used to initialize the terminal
  1509. Xin a mode suitable for
  1510. X.IR nroff .
  1511. X.TP 10
  1512. X.I twrest\^
  1513. Xset of characters used to restore the terminal to
  1514. Xnormal mode.
  1515. X.TP 10
  1516. X.I twnl\^
  1517. Xset of characters used to move down one line.
  1518. X.TP 10
  1519. X.I hlr\^
  1520. Xset of characters used to move up one-half line.
  1521. X.TP 10
  1522. X.I hlf\^
  1523. Xset of characters used to move down one-half line.
  1524. X.TP 10
  1525. X.I flr\^
  1526. Xset of characters used to move up one line.
  1527. X.TP 10
  1528. X.I bdon\^
  1529. Xset of characters used to turn on hardware boldface mode,
  1530. Xif any.
  1531. X.I Nroff\^
  1532. Xassumes that boldface mode is reset automatically by the
  1533. X.I twnl\^
  1534. Xstring, because many letter-quality printers reset the boldface
  1535. Xmode when they receive a carriage return;
  1536. Xthe
  1537. X.I twnl\^
  1538. Xstring should include whatever characters are necessary to
  1539. Xreset the boldface mode.
  1540. X.TP 10
  1541. X.I bdoff\^
  1542. Xset of characters used to turn off hardware boldface mode,
  1543. Xif any.
  1544. X.TP 10
  1545. X.I iton\^
  1546. Xset of characters used to turn on hardware italics mode,
  1547. Xif any.
  1548. X.TP 10
  1549. X.I itoff\^
  1550. Xset of characters used to turn off hardware italics mode,
  1551. Xif any.
  1552. X.TP 10
  1553. X.I ploton\^
  1554. Xset of characters used to turn on hardware plot mode
  1555. X(for Diablo type mechanisms), if any.
  1556. X.TP 10
  1557. X.I plotoff\^
  1558. Xset of characters used to turn off hardware plot mode
  1559. X(for Diablo type mechanisms), if any.
  1560. X.TP 10
  1561. X.I up\^
  1562. Xset of characters used to move up one resolution unit
  1563. X(Vert) in plot mode, if any.
  1564. X.TP 10
  1565. X.I down\^
  1566. Xset of characters used to move down one resolution unit
  1567. X(Vert) in plot mode, if any.
  1568. X.TP 10
  1569. X.I right\^
  1570. Xset of characters used to move right one resolution unit
  1571. X(Hor) in plot mode, if any.
  1572. X.TP 10
  1573. X.I left\^
  1574. Xset of characters used to move left one resolution unit
  1575. X(Hor) in plot mode, if any.
  1576. X.TP 10
  1577. X.I codetab\^
  1578. Xdefinition of characters needed to print an
  1579. X.I nroff\^
  1580. Xcharacter
  1581. Xon the terminal.
  1582. XThe first byte is the number of character units (Char) needed to hold the
  1583. Xcharacter; i.e., ``\\001'' is one unit wide, ``\\002'' is two
  1584. Xunits wide, etc.  The high-order bit (0200) is on if
  1585. Xthe character is to be underlined in underline mode
  1586. X(.ul).
  1587. XThe rest of the bytes are the characters used to produce the character in
  1588. Xquestion.  If the character has the sign (0200) bit on,
  1589. Xit is a code to move the terminal in plot mode.  It is
  1590. Xencoded as:
  1591. X.RS
  1592. X.IP "0100 bit on" 15
  1593. Xvertical motion.
  1594. X.IP "0100 bit off" 15
  1595. Xhorizontal motion.
  1596. X.IP "040 bit on" 15
  1597. Xnegative (up or left) motion.
  1598. X.IP "040 bit off" 15
  1599. Xpositive (down or right) motion.
  1600. X.IP "037 bits" 15
  1601. Xnumber of such motions to make.
  1602. X.RE
  1603. X.TP 10
  1604. X.I zzz\^
  1605. Xa zero terminator at the end.
  1606. X.PP
  1607. XAll quantities which are in units of fractions of an inch should
  1608. Xbe expressed as
  1609. X.RI INCH* num / denom ,
  1610. Xwhere
  1611. X.I num\^
  1612. Xand
  1613. X.I denom\^
  1614. Xare respectively the numerator and denominator of the fraction; i.e.,
  1615. X1/48 of an inch would be written as ``INCH/48''.
  1616. X.PP
  1617. XIf any sequence of characters does not pertain to the output device,
  1618. Xthat sequence should be given as a null string.
  1619. X.PP
  1620. XIf you have a source license:
  1621. X.br
  1622. XThe source code for the terminal
  1623. X.I name\^
  1624. Xlives in the directory /usr/src/cmd/text/roff.d/terms.d in a file called
  1625. X.BI tab name .c. 
  1626. XWhen a new terminal type is added, the file
  1627. X.I maketerms.c\^
  1628. Xshould be updated to `#include' the source to that driving table;
  1629. Xnote that the various terminal types are grouped into ``parts'' labelled
  1630. X.BR PART1 ,
  1631. X.BR PART2 ,
  1632. Xand
  1633. X.BR PART3 .
  1634. XIf necessary, more parts can be added.  Other changes necessary to
  1635. X.I maketerms.c\^
  1636. Xare left as an exercise to the reader.
  1637. XThe makefile
  1638. X.I terms.mk\^
  1639. Xin that directory should then be updated.
  1640. X.PP
  1641. XIf you do not have source license, but have Bruce Townsend's
  1642. X.I table\^
  1643. Xutility:
  1644. X.br
  1645. XThe source code for the terminal
  1646. X.I name\^
  1647. Xis in a file called
  1648. X.BI tab name .c.
  1649. XWhen a new terminal type is added, the file
  1650. X.I Makefile\^
  1651. Xin the same directory should be updated.
  1652. XJust add the name
  1653. X.BI tab name
  1654. Xto the definition of
  1655. X.BR TABFILES .
  1656. XThen type
  1657. X.BI "make tab" name.
  1658. XStore the result in
  1659. X.B /usr/lib/term.
  1660. X.SH FILES
  1661. X/usr/lib/term/tab\f2name\fP    driving tables
  1662. X.br
  1663. Xtab\f2name\fP.c    source for driving tables
  1664. X.SH SEE ALSO
  1665. Xtroff(1), term(7)
  1666. END_OF_FILE
  1667. if test 6726 -ne `wc -c <'term.5'`; then
  1668.     echo shar: \"'term.5'\" unpacked with wrong size!
  1669. fi
  1670. # end of 'term.5'
  1671. fi
  1672. if test -f 'termtab.c' -a "${1}" != "-c" ; then 
  1673.   echo shar: Will not clobber existing file \"'termtab.c'\"
  1674. else
  1675. echo shar: Extracting \"'termtab.c'\" \(2812 characters\)
  1676. sed "s/^X//" >'termtab.c' <<'END_OF_FILE'
  1677. X/*
  1678. X * termtab.c -- common declarations for nroff table conversion
  1679. X *
  1680. X * This code brought to you as a public service by Eric S. Raymond, Feb 1988
  1681. X * and is copyrighted (c)1988 by the author. Use, distribute, and mangle
  1682. X * freely, but don't try to make money selling it unless you're going to send
  1683. X * me a cut. Send bug reports, love letters and death threats to eric@snark
  1684. X * aka ...!rutgers!vu-vlsi!snark!eric.
  1685. X */
  1686. X/*LINTLIBRARY*/
  1687. X#include <stdio.h>
  1688. X#include "termtab.h"
  1689. X
  1690. Xextern char *strcpy();
  1691. Xextern void exit();
  1692. X
  1693. Xchar *ntnames[] =    /* [nt]roff character name translation */
  1694. X{
  1695. X" ", "!","\"", "#", "$", "%", "&", "'",
  1696. X"(", ")", "*", "+", ",", "-", ".", "/",
  1697. X"0", "1", "2", "3", "4", "5", "6", "7",
  1698. X"8", "9", ":", ";", "<", "=", ">", "?",
  1699. X"@", "A", "B", "C", "D", "E", "F", "G",
  1700. X"H", "I", "J", "K", "L", "M", "N", "O",
  1701. X"P", "Q", "R", "S", "T", "U", "V", "W",
  1702. X"X", "Y", "Z", "[", "\\","]", "^", "_",
  1703. X"`", "a", "b", "c", "d", "e", "f", "g",
  1704. X"h", "i", "j", "k", "l", "m", "n", "o",
  1705. X"p", "q", "r", "s", "t", "u", "v", "w",
  1706. X"x", "y", "z", "{", "|", "}", "~","\\|",
  1707. X"hy", "bu", "sq", "em", "ru", "14", "12", "34", 
  1708. X"\\-","fi", "fl", "ff", "Fi", "Fl", "de", "dg", 
  1709. X"sc", "fm", "aa", "ga", "ul", "sl", "\\^", "\\ ", 
  1710. X"*a", "*b", "*g", "*d", "*e", "*z", "*y", "*h", 
  1711. X"*i", "*k", "*l", "*m", "*n", "*c", "*o", "*p", 
  1712. X"*r", "*s", "*t", "*u", "*f", "*x", "*q", "*w", 
  1713. X"*G", "*D", "*H", "*L", "*C", "*P", "*S", "*T", 
  1714. X"*U", "*F", "*Q", "*W", "sr", "ts", "rn", ">=", 
  1715. X"<=", "==", "mi", "~=", "ap", "!=", "->", "<-", 
  1716. X"ua", "da", "eq", "mu", "di", "+-", "cu", "ca", 
  1717. X"sb", "sp", "ib", "ip", "if", "pd", "gr", "no", 
  1718. X"is", "pt", "es", "mo", "pl", "rg", "co", "br", 
  1719. X"ct", "dd", "rh", "lh", "**", "bs", "or", "ci", 
  1720. X"lt", "lb", "rt", "rb", "lk", "rk", "bv", "lf", 
  1721. X"rf", "lc", "rc",
  1722. X(char *)NULL
  1723. X };
  1724. X
  1725. Xvoid newstrings(sp)
  1726. Xstrtab *sp;
  1727. X{
  1728. X    sp->c_end = sp->c_data;
  1729. X}
  1730. X
  1731. Xchar *addstring(string, pp)
  1732. Xstrtab    *pp;
  1733. Xchar    *string;
  1734. X{
  1735. X    pp->c_pointer[pp->n_strings] = pp->c_end;
  1736. X    pp->c_end += (pp->c_length[pp->n_strings] = strlen(string)) + 1;
  1737. X    if (pp->c_end >= pp->c_data + C_SIZE)
  1738. X    {
  1739. X    (void) fprintf(stderr, "Table size too small, increase it!\n");
  1740. X    exit(1);
  1741. X    }
  1742. X    return(strcpy(pp->c_pointer[pp->n_strings++], string));
  1743. X}
  1744. X
  1745. Xint char_comp(str1, str2, len)
  1746. Xchar    *str1, *str2;
  1747. Xint    len;
  1748. X{
  1749. X    while (len--)
  1750. X    if (*str1++ != *str2++)
  1751. X        return(1);
  1752. X    return(0);
  1753. X}
  1754. X
  1755. Xint findstring(string, pp)
  1756. Xstrtab    *pp;
  1757. Xchar    *string;
  1758. X{
  1759. X    int    c_len, s_len, i;
  1760. X
  1761. X    for (i = 0; i < pp->n_strings; i++)
  1762. X    {
  1763. X    if ((c_len = pp->c_length[i]) >= (s_len = strlen(string))) {
  1764. X        if (!char_comp (string, pp->c_pointer[i] + c_len - s_len, s_len))
  1765. X        return (pp->c_pointer[i] + c_len - s_len - pp->c_data);
  1766. X    }
  1767. X    }
  1768. X    (void) fprintf(stderr, "Serious bug! string not found in table\n");
  1769. X    exit(1);
  1770. X    /* NOTREACHED */
  1771. X}
  1772. X
  1773. X/* termtab.c ends here */
  1774. END_OF_FILE
  1775. if test 2812 -ne `wc -c <'termtab.c'`; then
  1776.     echo shar: \"'termtab.c'\" unpacked with wrong size!
  1777. fi
  1778. # end of 'termtab.c'
  1779. fi
  1780. if test -f 'termtab.h' -a "${1}" != "-c" ; then 
  1781.   echo shar: Will not clobber existing file \"'termtab.h'\"
  1782. else
  1783. echo shar: Extracting \"'termtab.h'\" \(2551 characters\)
  1784. sed "s/^X//" >'termtab.h' <<'END_OF_FILE'
  1785. X/* termtab.h -- declaration of nroff terminal driver internal representation */
  1786. X
  1787. X/* you'll probably never need to change these */
  1788. X#define CHARMIN    32            /* minimum ASCII char nroff uses */
  1789. X#define CHARMAX    256            /* size of ASCII character set */
  1790. X
  1791. X#define C_SIZE    10000    /* The maximum amount of character data allowed
  1792. X               in the initialized structure t - increase if
  1793. X               necessary */
  1794. X
  1795. Xtypedef struct    /* string table internals */
  1796. X{
  1797. X    char    c_data[C_SIZE];
  1798. X    char    *c_pointer[CHARMAX - CHARMIN];
  1799. X    int        c_length[CHARMAX - CHARMIN];
  1800. X    char    *c_end;
  1801. X    int        n_strings, c_size;
  1802. X}
  1803. Xstrtab;
  1804. X
  1805. Xtypedef struct
  1806. X{
  1807. X    char *name;
  1808. X    int bset;
  1809. X    int breset;
  1810. X    int Hor;
  1811. X    int Vert;
  1812. X    int Newline;
  1813. X    int Char;
  1814. X#ifdef KANJI
  1815. X    int Kchar;
  1816. X#endif KANJI
  1817. X    int Em;
  1818. X    int Halfline;
  1819. X    int Adj;
  1820. X    char *twinit;
  1821. X    char *twrest;
  1822. X    char *twnl;
  1823. X    char *hlr;
  1824. X    char *hlf;
  1825. X    char *flr;
  1826. X    char *bdon;
  1827. X    char *bdoff;
  1828. X    char *iton;
  1829. X    char *itoff;
  1830. X    char *ploton;
  1831. X    char *plotoff;
  1832. X    char *up;
  1833. X    char *down;
  1834. X    char *right;
  1835. X    char *left;
  1836. X    char *codetab[CHARMAX - CHARMIN];
  1837. X    char *zzz;
  1838. X
  1839. X    strtab    pool;
  1840. X}
  1841. Xnrtab_t;
  1842. X
  1843. X/*
  1844. X * The format of an old-style tab file is:
  1845. X *
  1846. X * Type    Name        Size on most machines    Description
  1847. X * ----    ----        ---------------------    -----------
  1848. X * int    c_size        4 bytes    - The amount of character data in bytes
  1849. X *                that follows the t_stor structure.
  1850. X *
  1851. X * nrext_t oldform    1000 bytes - This is the storage for the "t"
  1852. X *            structure with one change. All the elements
  1853. X *            of the t structure which were pointers to
  1854. X *            strings are now integer indexes to one
  1855. X *            large character array.
  1856. X *
  1857. X * char    array[c_size]    (variable size)- This is the storage for the strings
  1858. X *            pointed to by the indexes.
  1859. X *
  1860. X * The total size of the tabfile in bytes should be:
  1861. X *    c_size + sizeof (c_size) + sizeof (t_stor)
  1862. X */
  1863. X
  1864. Xtypedef struct        /* This structure will be stored in the tab file */
  1865. X{
  1866. X    int bset;
  1867. X    int breset;
  1868. X    int Hor;
  1869. X    int Vert;
  1870. X    int Newline;
  1871. X    int Char;
  1872. X    int Em;
  1873. X    int Halfline;
  1874. X    int Adj;
  1875. X    int twinit;
  1876. X    int twrest;
  1877. X    int twnl;
  1878. X    int hlr;
  1879. X    int hlf;
  1880. X    int flr;
  1881. X    int bdon;
  1882. X    int bdoff;
  1883. X    int iton;
  1884. X    int itoff;
  1885. X    int ploton;
  1886. X    int plotoff;
  1887. X    int up;
  1888. X    int down;
  1889. X    int right;
  1890. X    int left;
  1891. X    int codetab[CHARMAX - CHARMIN];
  1892. X    int zzz;
  1893. X}
  1894. Xnrext_t;
  1895. X
  1896. Xextern char *ntnames[];
  1897. Xextern void newstrings();
  1898. Xextern char *addstring();
  1899. Xextern int char_comp(), findstring();
  1900. Xextern nrtab_t *ditread(), *otread();
  1901. Xextern void ditwrite(), otwrite();
  1902. X
  1903. X/* termtab.h ends here */
  1904. END_OF_FILE
  1905. if test 2551 -ne `wc -c <'termtab.h'`; then
  1906.     echo shar: \"'termtab.h'\" unpacked with wrong size!
  1907. fi
  1908. # end of 'termtab.h'
  1909. fi
  1910. echo shar: End of archive 1 \(of 2\).
  1911. cp /dev/null ark1isdone
  1912. MISSING=""
  1913. for I in 1 2 ; do
  1914.     if test ! -f ark${I}isdone ; then
  1915.     MISSING="${MISSING} ${I}"
  1916.     fi
  1917. done
  1918. if test "${MISSING}" = "" ; then
  1919.     echo You have unpacked both archives.
  1920.     rm -f ark[1-9]isdone
  1921. else
  1922.     echo You still need to unpack the following archives:
  1923.     echo "        " ${MISSING}
  1924. fi
  1925. ##  End of shell archive.
  1926. exit 0
  1927.